import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { HttpExceptionFilter } from './filter/http-exception.filter';
import { TransformInterceptor } from '@/interceptors/transform.interceptor';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useGlobalFilters(new HttpExceptionFilter()); // 处理全局的错误
  app.useGlobalInterceptors(new TransformInterceptor()); // 处理统一的结果
  app.setGlobalPrefix('api/v1');
  app.enableCors(); // 处理跨域
  const config = new DocumentBuilder()
    .setTitle('Cats example') // api标题
    .setDescription('The cats API description') // api描述
    .setVersion('1.0')
    .addTag('cats')
    .build();
  const document = SwaggerModule.createDocument(app, config); // 设置swagger文档配置项
  SwaggerModule.setup('swagger', app, document);
  await app.listen(4001);
}

bootstrap();
